home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr48 / ned100.zip / EDITPKG.PAS < prev    next >
Pascal/Delphi Source File  |  1993-04-08  |  31KB  |  1,065 lines

  1. { FILE:  editpkg.pas }
  2.  
  3.  
  4.  
  5. unit EditPkg;
  6.  
  7.  
  8.  
  9. { ************************************************************************* }
  10. {                                                                           }
  11. { NOTICE:  Most of the following code was written by Borland International. }
  12. {          The code is for use by TP6.0 users.  Keep the copyright notice   }
  13. {          intact!                                                          }
  14. {                                                                           }
  15. {          Turbo Pascal 6.0                                                 }
  16. {          Turbo Vision Demo                                                }
  17. {          Copyright (c) 1990 by Borland International                      }
  18. {                                                                           }
  19. { This unit provides an interface to the NEWEDIT unit.  Specifically,       }
  20. { it initializes the buffers, contains all the editor dialogs, handles all  }
  21. { allocation and deallocation of the clipboard, and of course opens up      }
  22. { the appropriate edit window when requested.                               }
  23. {                                                                           }
  24. { The only item I've really changed is how the "heap" is set up for         }
  25. { use by the editor buffers.  You can search for it using the label         }
  26. { shown below.  All other labels in this unit are defined in the NEWEDIT    }
  27. { unit, they being mostly for dialog boxes and error messages.              }
  28. {                                                                           }
  29. { Search   Description:                                                     }
  30. { ------   ------------                                                     }
  31. {                                                                           }
  32. { HEAP   - Added a feature to allow maximum or minimum heap allocation      }
  33. {          for use by the editors buffers.                                  }
  34. {                                                                           }
  35. { Al Andersen - 02/29/92.                                                   }
  36. {                                                                           }
  37. { ************************************************************************* }
  38.  
  39.  
  40. {$O+,F+,X+,S-,D-}
  41.  
  42.  
  43.  
  44. interface
  45.  
  46.  
  47.  
  48. uses
  49.  
  50.   Objects,
  51.   Drivers,
  52.   Views,
  53.   Dialogs,
  54.   StdDlg,
  55.   MsgBox,
  56.   App,
  57.   Buffers,
  58.   CmdFile,
  59.   NewEdit;
  60.  
  61.  
  62. VAR
  63.  
  64.   Clip_Window : NewEdit.PEditWindow;      { Object to hold the clip board. }
  65.  
  66.  
  67.  
  68.   procedure Deallocate_The_Clipboard;
  69.   procedure Deallocate_The_Editor;
  70.  
  71.   procedure Initialize_The_Clipboard;
  72.   procedure Initialize_The_Editor;
  73.  
  74.   function  Open_Editor (File_Name : Objects.FNameStr;
  75.                          Visible   : Boolean) : NewEdit.PEditWindow;
  76.  
  77.   procedure Run_The_Editor;
  78.   procedure Show_ClipBoard;
  79.  
  80.  
  81.  
  82. implementation
  83.  
  84.  
  85.  
  86. { -------------------------------------------------------------------------- }
  87.  
  88.  
  89.  
  90. function Execute_Dialog (P : Dialogs.PDialog; Data : Pointer) : Word;
  91.  
  92.  
  93.   { -------------------------------------------------------- }
  94.   {                                                          }
  95.   { This function places the editor dialogs on the desktop   }
  96.   { and takes care of seting/getting data options from them. }
  97.   {                                                          }
  98.   { -------------------------------------------------------- }
  99.  
  100.  
  101. VAR
  102.  
  103.   Result : Word; { Holds result of trying to ExecView onto Desktop. }
  104.  
  105. begin
  106.  
  107.   Result := Views.cmCancel;
  108.  
  109.   P := PDialog (App.Application^.ValidView (P));
  110.  
  111.   if P <> nil then
  112.   begin
  113.  
  114.     if Data <> nil then
  115.       P^.SetData (Data^);
  116.  
  117.     Result := App.DeskTop^.ExecView (P);
  118.  
  119.     if (Result <> Views.cmCancel) and (Data <> nil) then
  120.       P^.GetData (Data^);
  121.  
  122.     Dispose (P, Done);
  123.  
  124.   end;
  125.  
  126.   Execute_Dialog := Result;
  127.  
  128.  
  129. end; { Execute_Dialog }
  130.  
  131.  
  132.  
  133. { -------------------------------------------------------------------------- }
  134.  
  135.  
  136.  
  137. function Do_Edit_Dialog (Dialog : Integer; Info : Pointer) : Word; far;
  138.  
  139.  
  140.  
  141.   { ---------------------------------------------------------- }
  142.   {                                                            }
  143.   { This function creates the appropriate editor dialog boxes. }
  144.   {                                                            }
  145.   { ---------------------------------------------------------- }
  146.  
  147.  
  148. VAR
  149.  
  150.   Y_Position : Word; { Local variable to ensure ALL dialogs start in same spot. }
  151.  
  152.  
  153.  
  154.   { ------------------------------------------------------------------------ }
  155.  
  156.  
  157.  
  158.   function Create_Find_Dialog : Dialogs.PDialog;
  159.  
  160.  
  161.     { ----------------------------------------------------------- }
  162.     {                                                             }
  163.     { This is a local procedure that creates the FIND dialog box. }
  164.     {                                                             }
  165.     { ----------------------------------------------------------- }
  166.  
  167.  
  168.   VAR
  169.  
  170.     D        : Dialogs.PDialog;
  171.     R        : TRect;
  172.     Sub_View : Views.PView;
  173.  
  174.   begin
  175.  
  176.     R.Assign (21, Y_Position, 58, Y_Position + 11);
  177.     D := New (Dialogs.PDialog, Init (R, 'Find'));
  178.  
  179.     with D^ do
  180.     begin
  181.  
  182.       R.Assign (3, 3, 32, 4);
  183.       Sub_View := New (Dialogs.PInputLine, Init (R, 80));
  184.       Sub_View^.HelpCtx := CmdFile.hcDFindText;
  185.       Insert (Sub_View);
  186.  
  187.       R.Assign (2, 2, 15, 3);
  188.       Insert (New (Dialogs.PLabel, Init (R, '~T~ext to find', Sub_View)));
  189.       R.Assign (32, 3, 35, 4);
  190.       Insert (New (Dialogs.PHistory, Init (R, Dialogs.PInputLine (Sub_View), 10)));
  191.  
  192.       R.Assign (3, 5, 35, 7);
  193.       Sub_View := New (Dialogs.PCheckBoxes, Init (R,
  194.         NewSItem ('~C~ase sensitive',
  195.         NewSItem ('~W~hole words only',
  196.       nil))));
  197.       Sub_View^.HelpCtx := CmdFile.hcDCaseWhole;
  198.       Insert (Sub_View);
  199.  
  200.       R.Assign (7, 8, 17, 10);
  201.       Sub_View := New (Dialogs.PButton, Init (R, 'O~K~', Views.cmOk, Dialogs.bfDefault));
  202.       Sub_View^.HelpCtx := CmdFile.hcDOk;
  203.       Insert (Sub_View);
  204.  
  205.       Inc (R.A.X, 13);
  206.       Inc (R.B.X, 13);
  207.       Sub_View := New (Dialogs.PButton, Init (R, 'Cancel', Views.cmCancel, Dialogs.bfNormal));
  208.       Sub_View^.HelpCtx := CmdFile.hcDCancel;
  209.       Insert (Sub_View);
  210.  
  211.       SelectNext (False);
  212.  
  213.     end;
  214.  
  215.     Create_Find_Dialog := D;
  216.  
  217.  
  218.   end; { Create_Find_Dialog }
  219.  
  220.  
  221.  
  222.   { ------------------------------------------------------------------------ }
  223.  
  224.  
  225.  
  226.   function Create_Replace_Dialog : Dialogs.PDialog;
  227.  
  228.  
  229.  
  230.     { --------------------------------------------------------------------- }
  231.     {                                                                       }
  232.     { This is a local procedure that creates the SEARCH/REPLACE dialog box. }
  233.     {                                                                       }
  234.     { --------------------------------------------------------------------- }
  235.  
  236.  
  237.   VAR
  238.  
  239.     D        : Dialogs.PDialog;
  240.     R        : TRect;
  241.     Sub_View : Views.PView;
  242.  
  243.   begin
  244.  
  245.     R.Assign (20, Y_Position, 60, Y_Position + 16);
  246.     D := New (Dialogs.PDialog, Init (R, 'Replace'));
  247.  
  248.     with D^ do
  249.     begin
  250.  
  251.       R.Assign (2, 2, 15, 3);
  252.       Insert (New (Dialogs.PLabel, Init (R, '~T~ext to find', Sub_View)));
  253.  
  254.       R.Assign (3, 3, 34, 4);
  255.       Sub_View := New (Dialogs.PInputLine, Init (R, 80));
  256.       Sub_View^.HelpCtx := CmdFile.hcDFindText;
  257.       Insert (Sub_View);
  258.  
  259.       R.Assign (34, 3, 37, 4);
  260.       Insert (New (Dialogs.PHistory, Init (R, Dialogs.PInputLine (Sub_View), 10)));
  261.  
  262.       R.Assign (2, 5, 12, 6);
  263.       Insert (New (Dialogs.PLabel, Init (R, '~N~ew text', Sub_View)));
  264.  
  265.       R.Assign (3, 6, 34, 7);
  266.       Sub_View := New (Dialogs.PInputLine, Init (R, 80));
  267.       Sub_View^.HelpCtx := CmdFile.hcDReplaceText;
  268.       Insert (Sub_View);
  269.  
  270.       R.Assign (34, 6, 37, 7);
  271.       Insert (New (Dialogs.PHistory, Init (R, Dialogs.PInputLine (Sub_View), 11)));
  272.  
  273.       R.Assign (3, 8, 37, 12);
  274.       Sub_View := New (Dialogs.PCheckBoxes, Init (R,
  275.         NewSItem ('~C~ase sensitive',
  276.         NewSItem ('~W~hole words only',
  277.         NewSItem ('~P~rompt on replace',
  278.         NewSItem ('~R~eplace all',
  279.       nil))))));
  280.       Sub_View^.HelpCtx := CmdFile.hcDPromptReplace;
  281.       Insert (Sub_View);
  282.  
  283.       R.Assign (8, 13, 18, 15);
  284.       Sub_View := New (Dialogs.PButton, Init (R, 'O~K~', Views.cmOk, Dialogs.bfDefault));
  285.       Sub_View^.HelpCtx := CmdFile.hcDOk;
  286.       Insert (Sub_View);
  287.  
  288.       R.Assign (22, 13, 32, 15);
  289.       Sub_View := New (Dialogs.PButton, Init (R, 'Cancel', Views.cmCancel, Dialogs.bfNormal));
  290.       Sub_View^.HelpCtx := CmdFile.hcDCancel;
  291.       Insert (Sub_View);
  292.  
  293.       SelectNext (False);
  294.  
  295.     end;
  296.  
  297.     Create_Replace_Dialog := D;
  298.  
  299.  
  300.   end; { Create_Replace_Dialog }
  301.  
  302.  
  303.  
  304.   { ------------------------------------------------------------------------ }
  305.  
  306.  
  307.  
  308.   { JLINE - Start. }
  309.  
  310.   function Jump_Line_Dialog : Dialogs.PDialog;
  311.  
  312.  
  313.     { ---------------------------------------------------- }
  314.     {                                                      }
  315.     { This is a local function that brings up a dialog box }
  316.     { that asks the user which line number to jump to.     }
  317.     {                                                      }
  318.     { ---------------------------------------------------- }
  319.  
  320.  
  321.   VAR
  322.  
  323.     Line_Dialog : Dialogs.PDialog;
  324.     R           : TRect;
  325.     Sub_View    : Views.PView;
  326.  
  327.   Begin
  328.  
  329.     R.Assign (27, Y_Position, 53, Y_Position + 8);
  330.     Line_Dialog := New (Dialogs.PDialog, Init (R, 'Jump To'));
  331.  
  332.     with Line_Dialog^ do
  333.       begin
  334.  
  335.         R.Assign (3, 2, 15, 3);
  336.         Sub_View := New (Dialogs.PStaticText, Init (R, 'Line Number:'));
  337.         Insert (Sub_View);
  338.  
  339.         R.Assign (15, 2, 21, 3);
  340.         Sub_View := New (Dialogs.PInputLine, Init (R, 4));
  341.         Sub_View^.HelpCtx := CmdFile.hcDLineNumber;
  342.         Insert (Sub_View);
  343.  
  344.         R.Assign (21, 2, 24, 3);
  345.         Insert (New (Dialogs.PHistory, Init (R, Dialogs.PInputLine (Sub_View), 12)));
  346.  
  347.         R.Assign (2, 5, 12, 7);
  348.         Sub_View := New (Dialogs.PButton, Init (R, '~O~K', Views.cmOK, Dialogs.bfDefault));
  349.         Sub_View^.HelpCtx := CmdFile.hcDOk;
  350.         Insert (Sub_View);
  351.  
  352.         R.Assign (14, 5, 24, 7);
  353.         Sub_View := New (Dialogs.PButton, Init (R, '~C~ancel', Views.cmCancel, Dialogs.bfNormal));
  354.         Sub_View^.HelpCtx := CmdFile.hcDCancel;
  355.         Insert (Sub_View);
  356.  
  357.         SelectNext (False);
  358.  
  359.       end;
  360.  
  361.     Jump_Line_Dialog := Line_Dialog;
  362.  
  363.   end; { Jump_Line_Dialog; } { Added dialog to allow user to jump to line number. }
  364.  
  365.   { JLINE - Stop. }
  366.  
  367.  
  368.  
  369.   { ------------------------------------------------------------------------ }
  370.  
  371.  
  372.  
  373.   { REFDOC - Start. }
  374.  
  375.   function Reform_Doc_Dialog : Dialogs.PDialog;
  376.  
  377.  
  378.     { ----------------------------------------------------- }
  379.     {                                                       }
  380.     { This is a local function that brings up a dialog box  }
  381.     { that asks where to start reformatting the document.   }
  382.     {                                                       }
  383.     { ----------------------------------------------------- }
  384.  
  385.  
  386.   VAR
  387.  
  388.     R             : TRect;
  389.     Reform_Dialog : Dialogs.PDialog;
  390.     Sub_View      : Views.PView;
  391.  
  392.   Begin
  393.  
  394.     R.Assign (24, Y_Position, 56, Y_Position + 11);
  395.     Reform_Dialog := New (Dialogs.PDialog, Init (R, 'Reformat Document'));
  396.  
  397.     with Reform_Dialog^ do
  398.       begin
  399.  
  400.         R.Assign (2, 2, 30, 3);
  401.         Sub_View := New (Dialogs.PStaticText, Init (R, 'Please select where to begin'));
  402.         Insert (Sub_View);
  403.  
  404.         R.Assign (3, 3, 29, 4);
  405.         Sub_View := New (Dialogs.PStaticText, Init (R, 'reformatting the document:'));
  406.         Insert (Sub_View);
  407.  
  408.         R.Assign (50, 5, 68, 6);
  409.         Sub_View := New (Dialogs.PLabel, Init (R, 'Reformat Document', Sub_View));
  410.         Insert (Sub_View);
  411.  
  412.         R.Assign (5, 5, 26, 7);
  413.         Sub_View := New (Dialogs.PRadioButtons, Init (R,
  414.           NewSItem ('Current Line',
  415.           NewSItem ('Entire Document',
  416.         Nil))));
  417.         Sub_View^.HelpCtx := CmdFile.hcDReformDoc;
  418.         Insert (Sub_View);
  419.  
  420.         R.Assign (4, 8, 14, 10);
  421.         Sub_View := New (Dialogs.PButton, Init (R, '~O~K', Views.cmOK, Dialogs.bfDefault));
  422.         Sub_View^.HelpCtx := CmdFile.hcDOk;
  423.         Insert (Sub_View);
  424.  
  425.         R.Assign (17, 8, 27, 10);
  426.         Sub_View := New (Dialogs.PButton, Init (R, '~C~ancel', Views.cmCancel, Dialogs.bfNormal));
  427.         Sub_View^.HelpCtx := CmdFile.hcDCancel;
  428.         Insert (Sub_View);
  429.  
  430.         SelectNext (False);
  431.  
  432.       end;
  433.  
  434.       Reform_Doc_Dialog := Reform_Dialog;
  435.  
  436.  
  437.   end; { Reform_Doc_Dialog }
  438.  
  439.   { REFDOC - Stop. }
  440.  
  441.  
  442.  
  443.   { ------------------------------------------------------------------------ }
  444.  
  445.  
  446.  
  447.   { RMSET - Start. }
  448.   { WRAP  - Start. }
  449.  
  450.   function Right_Margin_Dialog : Dialogs.PDialog;
  451.  
  452.  
  453.     { ---------------------------------------------------- }
  454.     {                                                      }
  455.     { This is a local function that brings up a dialog box }
  456.     { that allows the user to change the Right_Margin.     }
  457.     {                                                      }
  458.     { ---------------------------------------------------- }
  459.  
  460.  
  461.   VAR
  462.  
  463.     R         : TRect;
  464.     RM_Dialog : Dialogs.PDialog;
  465.     Sub_View  : Views.PView;
  466.  
  467.   Begin
  468.  
  469.     R.Assign (27, Y_Position, 53, Y_Position + 8);
  470.     RM_Dialog := New (Dialogs.PDialog, Init (R, 'Right Margin'));
  471.  
  472.     with RM_Dialog^ do
  473.       begin
  474.  
  475.         R.Assign (5, 2, 13, 3);
  476.         Sub_View := New (Dialogs.PStaticText, Init (R, 'Setting:'));
  477.         Insert (Sub_View);
  478.  
  479.         R.Assign (13, 2, 18, 3);
  480.         Sub_View := New (Dialogs.PInputLine, Init (R, 3));
  481.         Sub_View^.HelpCtx := CmdFile.hcDRightMargin;
  482.         Insert (Sub_View);
  483.  
  484.         R.Assign (18, 2, 21, 3);
  485.         Insert (New (Dialogs.PHistory, Init (R, Dialogs.PInputLine (Sub_View), 13)));
  486.  
  487.         R.Assign (2, 5, 12, 7);
  488.         Sub_View := New (Dialogs.PButton, Init (R, 'OK', Views.cmOK, Dialogs.bfDefault));
  489.         Sub_View^.HelpCtx := CmdFile.hcDOk;
  490.         Insert (Sub_View);
  491.  
  492.         R.Assign (14, 5, 24, 7);
  493.         Sub_View := New (Dialogs.PButton, Init (R, '~C~ancel', Views.cmCancel, Dialogs.bfNormal));
  494.         Sub_View^.HelpCtx := CmdFile.hcDCancel;
  495.         Insert (Sub_View);
  496.  
  497.         SelectNext (False);
  498.  
  499.       end;
  500.  
  501.     Right_Margin_Dialog := RM_Dialog;
  502.  
  503.   end; { Right_Margin_Dialog; }
  504.  
  505.   { WRAP  - Stop. }
  506.   { RMSET - Stop. } { Added dialog to adjust right margin position. }
  507.  
  508.  
  509.  
  510.   { ------------------------------------------------------------------------ }
  511.  
  512.  
  513.  
  514.   { PRETAB - Start. }
  515.  
  516.   function Tab_Stop_Dialog : Dialogs.PDialog;
  517.  
  518.  
  519.     { ---------------------------------------------------- }
  520.     {                                                      }
  521.     { This is a local function that brings up a dialog box }
  522.     { that allows the user to set their own tab stops.     }
  523.     {                                                      }
  524.     { ---------------------------------------------------- }
  525.  
  526.  
  527.   VAR
  528.  
  529.     Index      : Integer;          { Local Indexing variable.                 }
  530.     R          : TRect;
  531.     Tab_Dialog : Dialogs.PDialog;
  532.     Sub_View   : Views.PView;
  533.     Tab_Stop   : String[2];        { Local string to print tab column number. }
  534.  
  535.   Begin
  536.  
  537.     R.Assign (0, Y_Position, 80, Y_Position + 8);
  538.     Tab_Dialog := New (Dialogs.PDialog, Init (R, 'Tab Settings'));
  539.  
  540.     with Tab_Dialog^ do
  541.       begin
  542.  
  543.         R.Assign (2, 2, 77, 3);
  544.         Sub_View := New (Dialogs.PStaticText, Init (R,
  545.                     ' ....|....|....|....|....|....|....|....|....|....|....|....|....|....|....'));
  546.         Insert (Sub_View);
  547.  
  548.         for Index := 1 to 7 do
  549.           begin
  550.             R.Assign (Index * 10 + 1, 1, Index * 10 + 3, 2);
  551.             Str (Index * 10, Tab_Stop);
  552.             Sub_View := New (Dialogs.PStaticText, Init (R, Tab_Stop));
  553.             Insert (Sub_View);
  554.           end;
  555.  
  556.         R.Assign (2, 3, 78, 4);
  557.         Sub_View := New (Dialogs.PInputLine, Init (R, 74));
  558.         Sub_View^.HelpCtx := CmdFile.hcDTabStops;
  559.         Insert (Sub_View);
  560.  
  561.         R.Assign (38, 5, 41, 6);
  562.         Insert (New (Dialogs.PHistory, Init (R, Dialogs.PInputLine (Sub_View), 14)));
  563.  
  564.         R.Assign (27, 5, 37, 7);
  565.         Sub_View := New (Dialogs.PButton, Init (R, '~O~K', Views.cmOK, Dialogs.bfDefault));
  566.         Sub_View^.HelpCtx := CmdFile.hcDOk;
  567.         Insert (Sub_View);
  568.  
  569.         R.Assign (42, 5, 52, 7);
  570.         Sub_View := New (Dialogs.PButton, Init (R, '~C~ancel', Views.cmCancel, Dialogs.bfNormal));
  571.         Sub_View^.HelpCtx := CmdFile.hcDCancel;
  572.         Insert (Sub_View);
  573.  
  574.         SelectNext (False);
  575.  
  576.       end;
  577.  
  578.     Tab_Stop_Dialog := Tab_Dialog;
  579.  
  580.   end { Tab_Stop_Dialog };
  581.  
  582.   { PRETAB - Stop. } { Added dialog to allow re-setting tab stops. }
  583.  
  584.  
  585.  
  586.   { ------------------------------------------------------------------------ }
  587.  
  588.  
  589.  
  590. VAR
  591.  
  592.   R : TRect;
  593.   T : TPoint;
  594.  
  595.  
  596. begin { Do_Edit_Dialog }
  597.  
  598.  
  599.  
  600.   { --------------------------------------------------------------------- }
  601.   {                                                                       }
  602.   { I want the dialog boxes to appear in relatively the same screen area, }
  603.   { regardless if the user is in normal or 43/50 line screen mode.        }
  604.   {                                                                       }
  605.   { --------------------------------------------------------------------- }
  606.  
  607.  
  608.   if Drivers.ScreenMode >= Drivers.smFont8x8 then
  609.     Y_Position := 7
  610.   else
  611.     Y_Position := 3;
  612.  
  613.  
  614.  
  615.   { ------------------------------------------------------ }
  616.   {                                                        }
  617.   { Figure out which dialog we want to put on the desktop. }
  618.   {                                                        }
  619.   { ------------------------------------------------------ }
  620.  
  621.  
  622.   case Dialog of
  623.  
  624.     edCreateError:
  625.       Do_Edit_Dialog := MsgBox.MessageBox ('Error creating file %s.',
  626.                         @Info, MsgBox.mfError + MsgBox.mfOkButton);
  627.  
  628.     edFind:
  629.       Do_Edit_Dialog := Execute_Dialog (Create_Find_Dialog, Info);
  630.  
  631.     edOutOfMemory:
  632.       Do_Edit_Dialog := MsgBox.MessageBox (^C'Not enough memory available.',
  633.                         nil, MsgBox.mfError + MsgBox.mfOkButton);
  634.  
  635.     edReadError:
  636.       Do_Edit_Dialog := MsgBox.MessageBox ('Error reading file %s.',
  637.                         @Info, MsgBox.mfError + MsgBox.mfOkButton);
  638.  
  639.     edReplace:
  640.       Do_Edit_Dialog := Execute_Dialog (Create_Replace_Dialog, Info);
  641.  
  642.     edSaveAs:
  643.       Do_Edit_Dialog := Execute_Dialog (New (StdDlg.PFileDialog, Init ('*.*',
  644.                        'Save file as', '~N~ame', StdDlg.fdOkButton, 101)), Info);
  645.  
  646.     edSaveModify:
  647.       Do_Edit_Dialog := MsgBox.MessageBox ('%s has been modified. Save?',
  648.                         @Info, MsgBox.mfInformation + MsgBox.mfYesNoCancel);
  649.  
  650.     edSaveUntitled:
  651.       Do_Edit_Dialog := Msgbox.MessageBox (^C'Save untitled file?',
  652.                         nil, MsgBox.mfInformation + MsgBox.mfYesNoCancel);
  653.  
  654.     edSearchFailed:
  655.       Do_Edit_Dialog := MsgBox.MessageBox (^C'Search string not found.',
  656.                         nil, MsgBox.mfError + MsgBox.mfOkButton);
  657.  
  658.     edWriteError:
  659.       Do_Edit_Dialog := MsgBox.MessageBox ('Error writing file %s.',
  660.                         @Info, MsgBox.mfError + MsgBox.mfOkButton);
  661.  
  662.     edReplacePrompt:
  663.       begin
  664.  
  665.         { Avoid placing the dialog on the same line as the cursor }
  666.  
  667.         R.Assign (0, 1, 40, 8);
  668.         R.Move ((App.Desktop^.Size.X - R.B.X) div 2, 0);
  669.         Desktop^.MakeGlobal (R.B, T);
  670.         Inc (T.Y);
  671.  
  672.         if TPoint (Info).Y <= T.Y then
  673.           R.Move (0, Desktop^.Size.Y - R.B.Y - 2);
  674.  
  675.         Do_Edit_Dialog := Msgbox.MessageBoxRect (R, ^C'Replace this occurence?',
  676.                           nil, MsgBox.mfYesNoCancel + MsgBox.mfInformation);
  677.  
  678.       end;
  679.  
  680.  
  681.  
  682.     { JLINE - Start. }
  683.  
  684.     edJumpToLine:
  685.       Do_Edit_Dialog := Execute_Dialog (Jump_Line_Dialog, Info);
  686.  
  687.     { JLINE - Stop. } { Added new cases to allow jumping to a line number. }
  688.  
  689.  
  690.  
  691.     { PRETAB - Start. }
  692.  
  693.     edSetTabStops:
  694.       Do_Edit_Dialog := Execute_Dialog (Tab_Stop_Dialog, Info);
  695.  
  696.     { PRETAB - Stop. } { Added new cases to support re-setting tab stops. }
  697.  
  698.  
  699.  
  700.     { WRAP - Start. }
  701.  
  702.  
  703.  
  704.     edPasteNotPossible:
  705.       Do_Edit_Dialog := MsgBox.MessageBox (^C'WORDWRAP ON:  Paste not possible' + #13
  706.                                            + ' in current margins when at end'  + #13
  707.                                            + ' of line.',
  708.                         nil, MsgBox.mfError + MsgBox.mfOkButton);
  709.  
  710.  
  711.  
  712.     { REFDOC - Start. }
  713.  
  714.     edReformatDocument:
  715.       Do_Edit_Dialog := Execute_Dialog (Reform_Doc_Dialog, Info);
  716.  
  717.     { REFDOC - Stop. }
  718.  
  719.  
  720.  
  721.     edReformatNotAllowed:
  722.       Do_Edit_Dialog := MsgBox.MessageBox (^C'You must turn on wordwrap' + #13
  723.                                           +^C'before you can reformat.',
  724.                         nil, MsgBox.mfError + MsgBox.mfOkButton);
  725.  
  726.     edReformNotPossible:
  727.       Do_Edit_Dialog := MsgBox.MessageBox (^C'Paragraph reformat not possible.'   + #13
  728.                                            + ' while trying to wrap current line' + #13
  729.                                            + ' with current margins.',
  730.                         nil, MsgBox.mfError + MsgBox.mfOkButton);
  731.  
  732.     edReplaceNotPossible:
  733.       Do_Edit_Dialog := MsgBox.MessageBox (^C'WORDWRAP ON:  Replace not possible' + #13
  734.                                            + ' in current margins when at end of' + #13
  735.                                            + ' line.',
  736.                         nil, MsgBox.mfError + MsgBox.mfOkButton);
  737.  
  738.  
  739.  
  740.     { RMSET- Start. }
  741.  
  742.     edRightMargin:
  743.       Do_Edit_Dialog := Execute_Dialog (Right_Margin_Dialog, Info);
  744.  
  745.     { RMSET - STOP. } { Added new cases to support right margin settings. }
  746.  
  747.  
  748.  
  749.     edWrapNotPossible:
  750.       Do_Edit_Dialog := MsgBox.MessageBox (^C'WORDWRAP ON:  Wordwrap not possible' + #13
  751.                                            + ' in current margins with continuous' + #13
  752.                                            + ' line.',
  753.                          nil, MsgBox.mfError + MsgBox.mfOKButton);
  754.  
  755.  
  756.  
  757.     { WRAP - Stop. } { Added new cases to support wordwrap and paragraph reformatting. }
  758.  
  759.  
  760.   else
  761.  
  762.     MsgBox.MessageBox (^C'Unknown dialog requested!', nil,
  763.                        MsgBox.mfError + MsgBox.mfOkButton);
  764.  
  765.   end;
  766.  
  767.  
  768. end; { Do_Edit_Dialog }
  769.  
  770.  
  771.  
  772. { -------------------------------------------------------------------------- }
  773.  
  774.  
  775.  
  776. procedure Deallocate_The_Clipboard;
  777.  
  778.  
  779.   { ----------------------------------------------------- }
  780.   {                                                       }
  781.   { This procedure disposes of the clipboard.  It is used }
  782.   { by the NEDEMO program when saving a desktop file.     }
  783.   {                                                       }
  784.   { ----------------------------------------------------- }
  785.  
  786.  
  787. begin
  788.  
  789.   if Clip_Window = nil then
  790.     Exit;
  791.  
  792.   Dispose (NewEdit.Clipboard, Done);
  793.   NewEdit.Clipboard := nil;
  794.   Dispose (Clip_Window, Done);
  795.  
  796.  
  797. end; { Deallocate_The_Clipboard }
  798.  
  799.  
  800.  
  801. { -------------------------------------------------------------------------- }
  802.  
  803.  
  804.  
  805. procedure Deallocate_The_Editor;
  806.  
  807.  
  808.   { --------------------------------------------------------- }
  809.   {                                                           }
  810.   { This procedure deallocates the editor buffer from memory. }
  811.   {                                                           }
  812.   { --------------------------------------------------------- }
  813.  
  814.  
  815. begin
  816.  
  817.   Buffers.DoneBuffers;
  818.  
  819.  
  820. end; { Deallocate_The_Editor }
  821.  
  822.  
  823.  
  824. { -------------------------------------------------------------------------- }
  825.  
  826.  
  827.  
  828. procedure Initialize_The_Clipboard;
  829.  
  830.  
  831.  
  832.   { ----------------------------------------------------- }
  833.   {                                                       }
  834.   { Set up a clipboard so editor can cut and paste text.  }
  835.   { We place this here because we also need to reallocate }
  836.   { a new clipboard everytime we save a desktop to disk.  }
  837.   {                                                       }
  838.   { ----------------------------------------------------- }
  839.  
  840.  
  841. begin
  842.  
  843.   Clip_Window := Open_Editor('', False);
  844.  
  845.   if Clip_Window <> nil then
  846.     begin
  847.       NewEdit.Clipboard := Clip_Window^.Editor;
  848.       NewEdit.Clipboard^.CanUndo := False;
  849.       Clip_Window^.HelpCtx := CmdFile.hcClipBoard;
  850.     end;
  851.  
  852.  
  853. end; { Initialize_The_Clipboard }
  854.  
  855.  
  856.  
  857. { -------------------------------------------------------------------------- }
  858.  
  859.  
  860.  
  861. procedure Initialize_The_Editor;
  862.  
  863.  
  864.  
  865.   { ----------------------------------------------------------------- }
  866.   {                                                                   }
  867.   { This procedure sets aside a bit of memory for the editor buffers. }
  868.   {                                                                   }
  869.   { ----------------------------------------------------------------- }
  870.  
  871.  
  872. CONST
  873.  
  874.   { HEAP - Start. }
  875.  
  876.   Edit_Buffer_Size = 32 * (1024 div 16);  { 32K buffer for the editor.      }
  877.  
  878.   { HEAP - Stop. } { Change the 32K default to whatever you require.        }
  879.  
  880. VAR
  881.  
  882.   The_Heap : Word;                        { Variable to show where heap is. }
  883.  
  884. begin
  885.  
  886.  
  887.  
  888.   { --------------------------------------------------------------------- }
  889.   {                                                                       }
  890.   { Calculate where the heap is and set aside a memory buffer for editor. }
  891.   { Note the line commented out in the IF statement.  ONLY means that     }
  892.   { your edit buffer size will be limited to what you want.  EXCEPT means }
  893.   { that your edit buffer size will be limited to memory left on the heap }
  894.   { minus the amount you want (everything BUT).  Comment out the line     }
  895.   { you DON'T want to use.                                                }
  896.   {                                                                       }
  897.   { --------------------------------------------------------------------- }
  898.  
  899.  
  900.   The_Heap := PtrRec (HeapEnd).Seg - PtrRec (HeapPtr).Seg;
  901.  
  902.   if The_Heap > Edit_Buffer_Size then
  903.  
  904.     { HEAP - Start. }
  905.  
  906.     { Buffers.BufHeapSize := Edit_Buffer_Size }         { ONLY what we want    }
  907.     Buffers.BufHeapSize := The_Heap - Edit_Buffer_Size  { EXCEPT what we want. }
  908.  
  909.     { HEAP - Stop. } { Read the above comment box. }
  910.  
  911.   else
  912.     Buffers.BufHeapSize := 0;
  913.  
  914.   Buffers.InitBuffers;
  915.  
  916.  
  917. end; { Initialize_The_Editor }
  918.  
  919.  
  920.  
  921. { -------------------------------------------------------------------------- }
  922.  
  923.  
  924.  
  925. function Open_Editor (File_Name : Objects.FNameStr; Visible : Boolean) : NewEdit.PEditWindow;
  926.  
  927.  
  928.   { ------------------------------------------------------- }
  929.   {                                                         }
  930.   { This is the actual function that opens up the edit view }
  931.   { and places it on the desktop.                           }
  932.   {                                                         }
  933.   { ------------------------------------------------------- }
  934.  
  935.  
  936. VAR
  937.  
  938.   P : Views.PView;
  939.   R : TRect;
  940.  
  941. begin
  942.  
  943.   DeskTop^.GetExtent (R);
  944.   P := Application^.ValidView (New (NewEdit.PEditWindow,
  945.        Init (R, File_Name, wnNoNumber)));
  946.  
  947.   if P <> nil then
  948.     begin
  949.  
  950.       if not Visible then
  951.         begin
  952.           P^.Hide;
  953.           P^.Options := P^.Options and not Views.ofTileable;
  954.         end
  955.       else
  956.         P^.HelpCtx := CmdFile.hcEditor_Commands;
  957.  
  958.  
  959.  
  960.       { ------------------------------------------------------------- }
  961.       {                                                               }
  962.       { This is a demonstration on how you can type cast variables    }
  963.       { and thereby override their NEWEDIT defaults.  If you really   }
  964.       { wanted to get fancy, you could add the appropriate parameters }
  965.       { to the Open_Editor function call and thereby have different   }
  966.       { defaults for each window.                                     }
  967.       {                                                               }
  968.       { ------------------------------------------------------------- }
  969.  
  970.  
  971.       with NewEdit.PEditWindow (P)^ do
  972.         begin
  973.           Editor^.AutoIndent := True;
  974.           Editor^.Word_Wrap := True;
  975.           Editor^.Right_Margin := 76;
  976.         end;
  977.  
  978.       Desktop^.Insert (P);
  979.  
  980.       Message (P, Drivers.evBroadcast, NewEdit.cmBludgeonStats, nil);
  981.  
  982.     end;
  983.  
  984.   Open_Editor := NewEdit.PEditWindow (P);
  985.  
  986.  
  987. end; { Open_Editor }
  988.  
  989.  
  990.  
  991. { -------------------------------------------------------------------------- }
  992.  
  993.  
  994.  
  995. procedure Run_The_Editor;
  996.  
  997.  
  998.   { --------------------------------------------------------------- }
  999.   {                                                                 }
  1000.   { This procedure is a "front end" to the Open_Editor function.    }
  1001.   { It brings up a dialog box that asks the user which file to use. }
  1002.   {                                                                 }
  1003.   { --------------------------------------------------------------- }
  1004.  
  1005.  
  1006. VAR
  1007.  
  1008.   D        : Dialogs.PDialog;
  1009.   FileName : Objects.FNameStr;
  1010.  
  1011. begin
  1012.  
  1013.   FileName := '*.*';
  1014.  
  1015.   D := new (StdDlg.PFileDialog, Init ('*.*', 'Edit A File',
  1016.             '~N~ame', StdDlg.fdOpenButton, 100));
  1017.  
  1018.   D^.HelpCtx := CmdFile.hcDName;
  1019.  
  1020.   if Execute_Dialog (D, @FileName) <> Views.cmCancel then
  1021.     Open_Editor (FileName, True);
  1022.  
  1023.  
  1024. end; { Run_The_Editor }
  1025.  
  1026.  
  1027.  
  1028. { -------------------------------------------------------------------------- }
  1029.  
  1030.  
  1031.  
  1032. procedure Show_ClipBoard;
  1033.  
  1034. begin
  1035.  
  1036.   Clip_Window^.Select;
  1037.   Clip_Window^.Show;
  1038.  
  1039.  
  1040. end; { Show_ClipBoard }
  1041.  
  1042.  
  1043.  
  1044. { -------------------------------------------------------------------------- }
  1045.  
  1046.  
  1047.  
  1048. begin { EditPkg }
  1049.  
  1050.  
  1051.  
  1052.   { --------------------------------------------- }
  1053.   {                                               }
  1054.   { Instantiate NewEdit.EditorDialog immediately. }
  1055.   { If you don't do it here, desktops loaded at   }
  1056.   { runtime will not have access to dialogs.      }
  1057.   {                                               }
  1058.   { --------------------------------------------- }
  1059.  
  1060.  
  1061.   NewEdit.EditorDialog := Do_Edit_Dialog;
  1062.  
  1063.  
  1064. end. { Unit EditPkg }
  1065.